class_name RelicDatabase
extends RefCounted

# 遗物数据库
static var relics: Dictionary = {}

static func initialize():
	_create_relics()

static func _create_relics():
	# 滑板车 - 每回合开始抽一张牌
	relics["skateboard"] = SkateboardRelic.new()
	
	# 汽车 - 增加最大生命值
	relics["car"] = CarRelic.new()
	
	# T恤 - 减少受到的伤害
	relics["tshirt"] = TShirtRelic.new()
	
	# 手机 - 每回合获得额外能量
	relics["phone"] = PhoneRelic.new()
	
	# 书包 - 增加手牌上限
	relics["backpack"] = BackpackRelic.new()
	
	# 眼镜 - 增加卡牌伤害
	relics["glasses"] = GlassesRelic.new()
	
	# 手表 - 每回合恢复生命值
	relics["watch"] = WatchRelic.new()
	
	# 耳机 - 免疫第一次伤害
	relics["headphones"] = HeadphonesRelic.new()
	
	# 笔记本 - 升级所有卡牌
	relics["notebook"] = NotebookRelic.new()
	
	# 笔 - 攻击时额外抽牌
	relics["pen"] = PenRelic.new()
	
	# 橡皮 - 移除负面状态
	relics["eraser"] = EraserRelic.new()
	
	# 尺子 - 增加护甲效果
	relics["ruler"] = RulerRelic.new()
	
	# 计算器 - 数学题伤害翻倍
	relics["calculator"] = CalculatorRelic.new()
	
	# 字典 - 英语题伤害翻倍
	relics["dictionary"] = DictionaryRelic.new()
	
	# 实验器材 - 物理化学题伤害翻倍
	relics["lab_equipment"] = LabEquipmentRelic.new()

static func get_relic(relic_id: String) -> Relic:
	if relics.has(relic_id):
		return relics[relic_id]
	return null

# 具体遗物实现
class SkateboardRelic extends Relic:
	func _init():
		super._init("skateboard", "滑板车", "每回合开始抽一张牌", GameData.RelicType.SKATEBOARD)
	
	func on_turn_start():
		var game_data = GameData.get_instance()
		game_data.draw_cards_to_hand()

class CarRelic extends Relic:
	func _init():
		super._init("car", "汽车", "增加20点最大生命值", GameData.RelicType.CAR)
	
	func on_obtain():
		var game_data = GameData.get_instance()
		game_data.player_max_health += 20
		game_data.player_health += 20

class TShirtRelic extends Relic:
	func _init():
		super._init("tshirt", "T恤", "减少1点受到的伤害", GameData.RelicType.TSHIRT)
	
	func on_take_damage(damage: int) -> int:
		return max(0, damage - 1)

class PhoneRelic extends Relic:
	func _init():
		super._init("phone", "手机", "每回合获得1点额外能量", GameData.RelicType.PHONE)
	
	func on_turn_start():
		var game_data = GameData.get_instance()
		game_data.player_energy += 1

class BackpackRelic extends Relic:
	func _init():
		super._init("backpack", "书包", "手牌上限+2", GameData.RelicType.SKATEBOARD)  # 复用类型
	
	func on_obtain():
		# 手牌上限在游戏逻辑中处理
		pass

class GlassesRelic extends Relic:
	func _init():
		super._init("glasses", "眼镜", "所有攻击卡伤害+2", GameData.RelicType.SKATEBOARD)
	
	func on_deal_damage(damage: int) -> int:
		return damage + 2

class WatchRelic extends Relic:
	func _init():
		super._init("watch", "手表", "每回合恢复3点生命值", GameData.RelicType.SKATEBOARD)
	
	func on_turn_start():
		var game_data = GameData.get_instance()
		game_data.player_health = min(game_data.player_health + 3, game_data.player_max_health)

class HeadphonesRelic extends Relic:
	func _init():
		super._init("headphones", "耳机", "免疫第一次受到的伤害", GameData.RelicType.SKATEBOARD)
	
	var damage_blocked: bool = false
	
	func on_take_damage(damage: int) -> int:
		if not damage_blocked:
			damage_blocked = true
			return 0
		return damage

class NotebookRelic extends Relic:
	func _init():
		super._init("notebook", "笔记本", "所有卡牌自动升级", GameData.RelicType.SKATEBOARD)
	
	func on_obtain():
		# 升级逻辑在卡牌系统中处理
		pass

class PenRelic extends Relic:
	func _init():
		super._init("pen", "笔", "使用攻击卡时抽一张牌", GameData.RelicType.SKATEBOARD)
	
	func on_deal_damage(damage: int) -> int:
		var game_data = GameData.get_instance()
		game_data.draw_cards_to_hand()
		return damage

class EraserRelic extends Relic:
	func _init():
		super._init("eraser", "橡皮", "移除所有负面状态", GameData.RelicType.SKATEBOARD)
	
	func on_obtain():
		# 负面状态移除逻辑
		pass

class RulerRelic extends Relic:
	func _init():
		super._init("ruler", "尺子", "护甲效果翻倍", GameData.RelicType.SKATEBOARD)
	
	func on_obtain():
		# 护甲翻倍逻辑在护甲系统中处理
		pass

class CalculatorRelic extends Relic:
	func _init():
		super._init("calculator", "计算器", "对数学题造成双倍伤害", GameData.RelicType.SKATEBOARD)
	
	func on_deal_damage(damage: int) -> int:
		# 检查目标是否为数学题
		var game_data = GameData.get_instance()
		if game_data.current_enemies.size() > 0:
			var enemy = game_data.current_enemies[0]
			if enemy.exam_type == "数学考试":
				return damage * 2
		return damage

class DictionaryRelic extends Relic:
	func _init():
		super._init("dictionary", "字典", "对英语题造成双倍伤害", GameData.RelicType.SKATEBOARD)
	
	func on_deal_damage(damage: int) -> int:
		var game_data = GameData.get_instance()
		if game_data.current_enemies.size() > 0:
			var enemy = game_data.current_enemies[0]
			if enemy.exam_type == "英语考试":
				return damage * 2
		return damage

class LabEquipmentRelic extends Relic:
	func _init():
		super._init("lab_equipment", "实验器材", "对物理化学题造成双倍伤害", GameData.RelicType.SKATEBOARD)
	
	func on_deal_damage(damage: int) -> int:
		var game_data = GameData.get_instance()
		if game_data.current_enemies.size() > 0:
			var enemy = game_data.current_enemies[0]
			if enemy.exam_type in ["物理考试", "化学考试"]:
				return damage * 2
		return damage
